<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>添加修改会员信息</title>
		<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css"  tppabs="https://www.layui.site/layui/dist/css/layui.css"  media="all">
	</head>
	<body>
		<form class="layui-form" lay-filter="layui-detail" target="form" action="../../../updateClientInfoAdd" method="post" style="margin: 10px 20px 0 20px;">  
			<fieldset class="layui-elem-field layui-border-cyan">
				<legend style="font-size: 15px;">会员信息</legend>
				<div class="layui-field-box">
					<div class="layui-form-item">
					    <div class="layui-inline">
					      <label class="layui-form-label">会员编号:</label>
					      <div class="layui-input-inline">
					        <input type="tel" name="menId" readonly="" id="menId" class="layui-input">
					      </div>
					    </div>
					    <div class="layui-inline">
					      <label class="layui-form-label">会员级别:</label>
					      <div class="layui-input-inline">
					        <select name="menTypeId">
					          <option value="">请选择会员级别</option>
					        </select>     
					      </div>
					    </div>
					</div>
					<div class="layui-form-item">
					    <div class="layui-inline">
					      <label class="layui-form-label">优惠方式:</label>
					      <div class="layui-input-inline">
							<select name="menPreferential">
							  <option value="打折">打折</option>
							  <option value="不打折">不打折</option>
							</select> 
					      </div>
					    </div>
					    <div class="layui-inline">
					      <label class="layui-form-label">会员名称:</label>
					      <div class="layui-input-inline">
					        <input type="text" name="menName" required="" class="layui-input">
					      </div>
					    </div>
					</div>
					<div class="layui-form-item">
					    <div class="layui-inline">
					      <label class="layui-form-label">会员积分:</label>
					      <div class="layui-input-inline">
					        <input type="tel" name="menPoint" class="layui-input">
					      </div>
					    </div>
						<div class="layui-inline">
						  <label class="layui-form-label"></label>
						  <div class="layui-input-inline">
						    <input type="checkbox" name="menPointUpgrade" title="该会员卡按积分升级" lay-skin="primary" value="1">
						  </div>
						</div>
					</div>
					<div class="layui-form-item">
					    <div class="layui-inline">
					      <label class="layui-form-label">联系电话:</label>
					      <div class="layui-input-inline">
					        <input type="tel" name="menPhone" lay-verify="required|phone" required="" class="layui-input">
					      </div>
					    </div>
						<div class="layui-inline">
						  <label class="layui-form-label"></label>
						  <div class="layui-input-inline">
						    <input type="checkbox" name="menStatus" title="启用该会员" lay-skin="primary" value="1"> 
						  </div>
						</div>
					</div>
					<div class="layui-form-item">
					    <div class="layui-inline">
					      <label class="layui-form-label">储存金额:</label>
					      <div class="layui-input-inline">
					        <input type="tel" name="menCardBalance" class="layui-input">
					      </div>
					    </div>
					    <div class="layui-inline">
					      <label class="layui-form-label">会员密码:</label>
					      <div class="layui-input-inline">
					        <input type="text" name="menPass" required="" class="layui-input">
					      </div>
					    </div>
					</div>
					<div class="layui-form-item" id="test6">
					    <div class="layui-inline">
					      <label class="layui-form-label">加入日期:</label>
					      <div class="layui-input-inline">
					        <input type="text" name="menStartDate" required=""  id="test-startDate-1" class="layui-input" placeholder="开始日期">
					      </div>
					    </div>
					    <div class="layui-inline">
					      <label class="layui-form-label">截止日期:</label>
					      <div class="layui-input-inline">
					        <input type="text" name="menFinalDate" id="test-endDate-1" class="layui-input" placeholder="结束日期">
					      </div>
					    </div>
					</div>
				</div>
			</fieldset>
			<div class="layui-form-item" style="text-align: center;height: 40px;">
			    <div class="layui-inline">
					<div class="layui-input-inline">
						<button type="submit" lay-submit="" class="layui-btn" lay-filter="submitId" >保存</button>
			        </div>
			    </div>
				<div class="layui-inline">
				    <div class="layui-input-inline">
						<button type="button" id="menberexit" class="layui-btn">退出</button>
				    </div>
				</div>
			</div>
		</form>
		<iframe name="form" id="form" style="display:none"></iframe>
		<script src="../../layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.use(['form' , 'laydate' , 'element' , 'table', 'layer'], function() {
				var tree = layui.tree
				    ,layer = layui.layer
					,table = layui.table
					,laydate = layui.laydate
					,element = layui.element
					,form = layui.form
					,$ = layui.jquery;
				$("#menberexit").click(function(){
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭 	
				})
				
				//下拉列表动态输入
				$(function(){
					$.get("../../../searchClientTypeInfo",function(obj){
						var data = obj.data;
						for(var i in data){
							$('select[name=menTypeId]').append(new Option(data[i].menTypeName,data[i].menTypeId));
						}
						//要重新解析这个结构
						form.render('select');
						//获取当前页面地址栏获取标记判断是增加还是修改
						var url = location.search.substring(1).substring(location.search.substring(1).length-4,location.search.substring(1).length);
						if(url == "true"){
							//会员id自动获取
							$.get("../../../searchClientIdInfo",{menId:"menId",table:"menmber_info"},function(obj){
								$("#menId").val(obj)
							})
						}else{//修改进行表单渲染，把父页面传过来的数据渲染到当前表单
							var obj = JSON.parse(parent.memberInfo);  //接收一个对象，不转form.val()无法渲染
							form.val();
							obj.menStartDate = layui.util.toDateString(obj.menStartDate, "yyyy-MM-dd");
							obj.menFinalDate = layui.util.toDateString(obj.menFinalDate, "yyyy-MM-dd");
							form.val('layui-detail' , obj);      //渲染表单
						}
					})	
				})
				//单击提交按钮事件，
				form.on('submit(submitId)', function(data){
					var url = location.search.substring(1).substring(location.search.substring(1).length-4,location.search.substring(1).length);
					//判断当时弹窗是添加会员信息还是修改会员信息
					if(url == "true"){
						$("#form").load(function(){
						     var text = $(this).contents().find("body").text(); //获取到的是json的字符串
						     var j = $.parseJSON(text);  //json字符串转换成json对象
							 if(j == "1"){
								 parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引
								 parent.location.reload();
							 }else{
								 layer.msg("添加失败");
							 }
						})
					}else{
						$.get("../../../updateClientInfo",data.field,function(obj){
							if(obj == 1){
								parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引
								parent.location.reload();
							}
						})
						return false;
					}
				});
				
				 //日期范围
				  laydate.render({
				    elem: '#test6'
				    //设置开始日期、日期日期的 input 选择器
				    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
				    ,range: ['#test-startDate-1', '#test-endDate-1']
				  });
				
				
			})
		</script>
	</body>
</html>
